package huawei.js2025;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

/**
 * 幼儿园分班
 */
public class Question4 {

    public List<String> fenBan(String s) {
        List<String> ban1 = new ArrayList<>();
        List<String> ban2 = new ArrayList<>();

        String[] split1 = s.split(" ");
        String pre = "";
        for (int i = 0; i < split1.length; i++) {
            String[] split = split1[i].split("/");

            if (i == 0) {
                ban1.add(split[0]);
            } else {
                if ("Y".equals(split[1])) {
                    if (ban1.contains(pre)) {
                        ban1.add(split[0]);
                    } else {
                        ban2.add(split[0]);
                    }
                } else {
                    if (ban1.contains(pre)) {
                        ban2.add(split[0]);
                    } else {
                        ban1.add(split[0]);
                    }
                }
            }
            pre = split[0];
        }
        List<String> result = new ArrayList<>();
        result.add(ban1.stream().sorted(String::compareTo).collect(Collectors.joining(" ")));
        result.add(ban2.stream().sorted(String::compareTo).collect(Collectors.joining(" ")));
        return result;
    }

    public static void main(String[] args) {
        Question4 question4 = new Question4();
        List<String> strings = question4.fenBan("1/N 2/Y 3/Y 4/N");

        for (String s : strings) {
            System.out.println(s);
        }
    }
}
